<?php
if ($store) {
    $package = unserialize($store->package_values);
    ?>
    <h1><span class="ico_createstore"></span><?= lang('label_edit_your_store') ?></h1>

    <ul class="breadcrumb">
        <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
        <li><a href="<?= base_url('store') ?>"><?= lang('label_store'); ?></a></li>
        <li><?= lang('label_edit_your_store') ?></li>
    </ul>


    <div class="page">
        <div id="steptap">

            <br />

            <div class="step_tap">
                <ul>
                    <?php
                    foreach ($pdetails as $pd) {
                        if ($pd->name == 'logo')
                            continue;
                        if ($pd->type != 'no' && $package[$pd->name] != 'false') {
                            ?>
                            <?php
                            if ($pd->name == 'storead') {
                                if ($package[$pd->name] == 'true_owner') {
                                    ?>
                                    <li class=""><a href="#<?= $pd->name ?>"><?= $pd->title ?></a></li>
                                    <?php
                                }
                            } else {
                                ?>
                                <li class=""><a href="#<?= $pd->name ?>"><?= $pd->title; if($pd->name == 'storename') {foreach ($pdetails as $ppd) { if($ppd->name == 'logo') echo ' & '.$ppd->title.'*';}} ?></a></li>
                            <?php } ?>
                            <?php
                        }
                    }
                    ?>

                </ul>
            </div>

            <br /><br />

            <form action="<?= current_url() ?>" method="post" class="forms" enctype="multipart/form-data">
                <?php
                foreach ($pdetails as $pd) {
                    if ($pd->name == 'logo')
                        continue;
                    if (isset($package[$pd->name])) {
                        if ($pd->type != 'no' && $package[$pd->name] != 'false') {
                            $inputnum = 0;
                            $pp = $package[$pd->name];
                            $pp = trim($pp);
                            if (is_numeric($pp)) {
                                $inputnum = $pp;
                            } else {
                                if (($pp == 'true' && $pd->name != 'storead') || $pp == 'banner') {
                                    $inputnum = 1;
                                } elseif ($pp == 'slider') {
                                    $inputnum = 3;
                                } elseif ($pd->name == 'storead') {
                                    if ($pp == 'true_owner')
                                        $inputnum = 2;
                                    else
                                        continue;
                                }else {
                                    $pp = explode('+', $pp);
                                    if (count($pp) > 1) {
                                        foreach ($pp as $p => $v) {
                                            if (is_numeric($v))
                                                $inputnum += $v;
                                            else
                                                $inputnum += 1;
                                        }
                                    }
                                }
                                if (!$inputnum)
                                    $inputnum = 1;
                            }
                            ?>
                            <div id='<?= $pd->name ?>'>
                                <?php if ($pd->name == 'storename') { ?>
                                    <?php for ($i = 1; $i <= $inputnum; $i++) { ?>
                                        <div class="text">
                                            <label for="storename"><?= $pd->title ?> :</label>
                                            <samp>
                                                <input type="text" name="storename" id="storename" class="input-user" value="<?= (form_val('storename')) ? form_val('storename') : (isset($storedetails['storename']) ? $storedetails['storename'] : ''); ?>" placeholder="<?= $pd->title ?>" />
                                            </samp>
                                        </div>
                                        <div class="browse">
                                            <label><?php foreach ($pdetails as $ppd) { if($ppd->name == 'logo') echo $ppd->title;} ?> :</label>
                                            <samp>
                                                <input type="file" id="slogo" name="logo" value="<?= (form_val("logo")) ? form_val("logo") : (isset($storedetails["logo"]) ? $storedetails["logo"] : ''); ?>" /><label for="slogo"></label><strong dir="ltr">{ 135px Width * 85px Height }</strong>

                                            </samp>
                                            <div style="text-align: center;width: 135px;height: 85px;background: #f5f5f5; border:3px solid #e0e0e0; float: none;clear: both;margin: 65px auto 0; overflow:hidden;">
                                                <?php if (isset($storedetails["logo"])) { ?>
                                                    <img src="<?= base_url(STORE_PATH . '/' . $storedetails["logo"]) ?>" style="width:135px; height:85px;" >
                                                <?php } ?>
                                            </div>
                                        </div>
                                    <?php } ?>

                                <?php } elseif ($pd->name == 'storebanner') { ?>
                                    <?php for ($i = 1; $i <= $inputnum; $i++) { ?>
                                        <div class="browse">
                                            <label><?= $pd->title . " $i" ?> :</label>
                                            <samp>
                                                <input type="file" id="storebanner_<?= $i ?>" name="storebanner_<?= $i ?>" value="<?= (form_val("storebanner_$i")) ? form_val("storebanner_$i") : (isset($storedetails["storebanner_$i"]) ? $storedetails["storebanner_$i"] : ''); ?>" /><label for="storebanner_<?= $i ?>"></label><strong dir="ltr">{ 965px Width  *  110px Height }</strong>
                                            </samp>
                                            <?php if (isset($storedetails["storebanner_$i"])) { ?>
                                                <div style="text-align: center;width: 735px; float: none;clear: both;margin: 65px auto 0; overflow:hidden; position:relative;">
                                                    <img src="<?= base_url(STORE_PATH . '/' . $storedetails["storebanner_$i"]) ?>" style="max-width:735px; margin:6px auto;" >
                                                    <a style="position: absolute;z-index: 99999;left: 45%;top: 40%;box-shadow: #fff 0 0 20px 10px;" class="store_but storedelete" href="<?= base_url("store/deleteimage/storebanner_$i") ?>"><?= lang('label_delete') ?></a>
                                                </div>
                                            <?php } ?>
                                        </div>
                                    <?php } ?>
                                <?php } elseif ($pd->name == 'storedescription') { ?>
                                    <?php for ($i = 1; $i <= $inputnum; $i++) { ?>
                                        <div class="textarea">
                                            <label for="storedescription"><?= $pd->title ?> :</label>
                                            <samp>
                                                <textarea id="storedescription" name="storedescription"><?= (form_val('storedescription')) ? form_val('storedescription') : (isset($storedetails['storedescription']) ? $storedetails['storedescription'] : ''); ?></textarea>
                                            </samp>
                                        </div>
                                    <?php } ?>
                                <?php } elseif ($pd->name == 'staticpages') { ?>
                                    <?php for ($i = 1; $i <= $inputnum; $i++) { ?>
                                        <br>
                                        <?php if (isset($pp[$i - 1]) && !is_numeric($pp[$i - 1])) { ?>
                                            <input type="hidden" name="staticpages_title[<?= trim($pp[$i - 1]) ?>]" value="<?= (form_val("staticpages_title=>" . trim($pp[$i - 1]))) ? form_val("staticpages_title=>" . trim($pp[$i - 1])) : lang('label_values_' . trim($pp[$i - 1])); ?>">
                                            <div class="textarea">
                                                <label for="staticpages_content<?= trim($pp[$i - 1]) ?>"><?= lang('label_values_' . trim($pp[$i - 1])) ?> :</label>
                                                <samp>
                                                    <textarea id="staticpages_content<?= trim($pp[$i - 1]) ?>" name="staticpages_content[<?= trim($pp[$i - 1]) ?>]"><?= (form_val("staticpages_content=>" . trim($pp[$i - 1]))) ? form_val("staticpages_content=>" . trim($pp[$i - 1])) : (isset($storedetails["staticpages_content"][trim($pp[$i - 1])]) ? $storedetails["staticpages_content"][trim($pp[$i - 1])] : '' ); ?></textarea>
                                                </samp>
                                            </div>

                                        <?php } else { ?>
                                            <div class="text">
                                                <label for="staticpages_title<?= $i ?>"><?= lang('label_title') ?> :</label>
                                                <samp>
                                                    <input type="text" name="staticpages_title[<?= $i ?>]" id="staticpages_title<?= $i ?>" class="input-user" value="<?= (form_val("staticpages_title=>$i")) ? form_val("staticpages_title=>$i") : (isset($storedetails["staticpages_title"][$i]) ? $storedetails["staticpages_title"][$i] : '' ); ?>" placeholder="<?= lang('label_title') . " $i" ?>" />
                                                </samp>
                                            </div>
                                            <div class="textarea">
                                                <label for="staticpages_content<?= $i ?>"><?= lang('label_content') ?> :</label>
                                                <samp>
                                                    <textarea id="staticpages_content<?= $i ?>" placeholder="<?= lang('label_title') . " $i" ?>" name="staticpages_content[<?= $i ?>]"><?= (form_val("staticpages_content=>$i")) ? form_val("staticpages_content=>$i") : (isset($storedetails["staticpages_content"][$i]) ? $storedetails["staticpages_content"][$i] : ''); ?></textarea>
                                                </samp>
                                            </div>
                                        <?php } ?>
                                        <hr>
                                    <?php } ?>

                                <?php } elseif ($pd->name == 'storead') { ?>
                                    <?php for ($i = 1; $i <= $inputnum; $i++) { ?>
                                        <div class="browse">
                                            <label><?= $pd->title . " $i" ?> :</label>
                                            <samp>
                                                <input type="file" id="storead_<?= $i ?>" name="storead_<?= $i ?>" value="<?= (form_val("storead_$i")) ? form_val("storead=>$i") : (isset($storedetails["storead_$i"]) ? $storedetails["storead_$i"] : ''); ?>" /><label for="storead_<?= $i ?>"></label><strong>{ 175px Max Width }</strong>
                                            </samp>
                                            <?php if (isset($storedetails["storead_$i"])) { ?>
                                                <div style="text-align: center;width: 735px; float: none;clear: both;margin: 65px auto 0; overflow:hidden; position:relative;">
                                                    <img src="<?= base_url(STORE_PATH . '/' . $storedetails["storead_$i"]) ?>" >
                                                    <a style="position: absolute;z-index: 99999;left: 45%;top: 40%;box-shadow: #fff 0 0 20px 10px;" class="store_but storedelete" href="<?= base_url("store/deleteimage/storead_$i") ?>"><?= lang('label_delete') ?></a>
                                                </div>
                                            <?php } ?>
                                        </div>
                                        <?php
                                    }
                                }
                                ?>
                            </div>
                            <?php
                        }
                    }
                }
                ?>

        </div>
    </div>

    <div class="submit">
        <input name="submit" value="<?= lang('label_save') ?>" type="submit"  />
    </div>


    </form>

<?php } else { ?>
    <?php show_404(); ?>
<?php } ?>

</div>
